package com.hiultra.archive.controller;

import com.hiultra.archive.domain.ArchiveRoomAlarm;
import com.hiultra.archive.domain.vo.IssuedParamVo;
import com.hiultra.archive.domain.vo.ResultEntity;
import com.hiultra.archive.service.IArcArchiveInfoInsertService;
import com.hiultra.archive.service.IArchiveRoomAlarmService;
import com.hiultra.archive.utils.sgsm.SM2Util;
import com.hiultra.common.core.controller.BaseController;
import com.hiultra.common.exception.ServiceException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

@Api(value = "/archive/arcArchiveInfoInsert")
@RestController
@RequestMapping("/archive/arcArchiveInfoInsert")
public class ArcArchiveInfoInsertController extends BaseController {

    @Autowired
    private IArcArchiveInfoInsertService arcArchiveInfoInsertService;

    /**
     * 档案盘点任务下发接口
     */
    @ApiOperation("档案任务下发接口")
    @PostMapping("/insertArchiveTask")
    @Transactional
    public ResultEntity insertArchiveTask(@RequestBody IssuedParamVo issuedParamVo)  {
        try {
            return arcArchiveInfoInsertService.insertArchiveTask(issuedParamVo);
        } catch (ParseException e) {
            return ResultEntity.error(e.getMessage());
        }catch (ServiceException e){
            return ResultEntity.error(e.getMessage());
        }
    }

    /**
     * 库位信息下发接口
     */
    @ApiOperation("库位信息下发接口")
    @PostMapping("/insertHouseLocationNoInfoIssuedTask")
    @Transactional
    public ResultEntity insertHouseLocationNoInfoIssuedTask(@RequestBody IssuedParamVo issuedParamVo)  {
        try {
            return arcArchiveInfoInsertService.insertArchiveTask(issuedParamVo);
        } catch (ParseException e) {
            return ResultEntity.error(e.getMessage());
        }catch (ServiceException e){
            return ResultEntity.error(e.getMessage());
        }
    }

    /**
     * 档案盘点任务下发接口
     */
    @ApiOperation("档案盘点任务下发接口")
    @PostMapping("/insertArchiveStocktakingTask")
    @Transactional
    public ResultEntity insertArchiveStocktakingTask(@RequestBody IssuedParamVo issuedParamVo)  {
        try {
            return arcArchiveInfoInsertService.insertArchiveTask(issuedParamVo);
        } catch (ParseException e) {
            return ResultEntity.error(e.getMessage());
        }catch (ServiceException e){
            return ResultEntity.error(e.getMessage());
        }
    }

    /**
     * 档案入库任务下发接口
     */
    @ApiOperation("档案入库任务下发接口")
    @PostMapping("/insertArchiveStorageTask")
    @Transactional
    public ResultEntity insertArchiveStorageTask(@RequestBody IssuedParamVo issuedParamVo)  {
        try {
            return arcArchiveInfoInsertService.insertArchiveTask(issuedParamVo);
        } catch (ParseException e) {
            return ResultEntity.error(e.getMessage());
        }catch (ServiceException e){
            return ResultEntity.error(e.getMessage());
        }
    }


    /**
     * 新增档案盒接口
     */
    @ApiOperation("新增档案盒接口")
    @PostMapping("/insertArchiveBox")
    @Transactional
    public ResultEntity insertArchiveBox(@RequestBody IssuedParamVo issuedParamVo)  {
        try {
            return arcArchiveInfoInsertService.insertArchiveTask(issuedParamVo);
        } catch (ParseException e) {
            return ResultEntity.error(e.getMessage());
        }catch (ServiceException e){
            return ResultEntity.error(e.getMessage());
        }
    }

    /**
     * 新增档案袋接口
     */
    @ApiOperation("新增档案袋接口")
    @PostMapping("/insertArchiveBag")
    @Transactional
    public ResultEntity insertArchiveBag(@RequestBody IssuedParamVo issuedParamVo)  {
        try {
            return arcArchiveInfoInsertService.insertArchiveTask(issuedParamVo);
        } catch (ParseException e) {
            return ResultEntity.error(e.getMessage());
        }catch (ServiceException e){
            return ResultEntity.error(e.getMessage());
        }
    }

    /**
     * 档案销毁任务下发
     */
    @ApiOperation("档案销毁任务下发")
    @PostMapping("/insertArchiveDesTask")
    @Transactional
    public ResultEntity insertArchiveDesTask(@RequestBody IssuedParamVo issuedParamVo) {
        try {
            return arcArchiveInfoInsertService.insertArchiveTask(issuedParamVo);
        } catch (ParseException e) {
            return ResultEntity.error(e.getMessage());
        }catch (ServiceException e){
            return ResultEntity.error(e.getMessage());
        }
    }

    /**
     * 盒间档案移位任务下发接口
     */
    @ApiOperation("盒间档案移位任务下发接口")
    @PostMapping("/insertArchiveBoxinnerMoveTask")
    @Transactional
    public ResultEntity insertArchiveBoxinnerMoveTask(@RequestBody IssuedParamVo issuedParamVo) {
        try {
            return arcArchiveInfoInsertService.insertArchiveTask(issuedParamVo);
        } catch (ParseException e) {
            return ResultEntity.error(e.getMessage());
        }catch (ServiceException e){
            return ResultEntity.error(e.getMessage());
        }
    }

    /**
     * 档案盒移位任务下发
     */
    @ApiOperation("档案盒移位任务下发")
    @PostMapping("/insertArchiveBoxMoveTask")
    @Transactional
    public ResultEntity insertArchiveBoxMoveTask(@RequestBody IssuedParamVo issuedParamVo) {
        try {
            return arcArchiveInfoInsertService.insertArchiveTask(issuedParamVo);
        } catch (ParseException e) {
            return ResultEntity.error(e.getMessage());
        }catch (ServiceException e){
            return ResultEntity.error(e.getMessage());
        }
    }

    /**
     * 档案借阅任务下发
     */
    @ApiOperation("档案借阅任务下发")
    @PostMapping("/insertArchiveBorrowTask")
    @Transactional
    public ResultEntity insertArchiveBorrowTask(@RequestBody IssuedParamVo issuedParamVo) {
        try {
            return arcArchiveInfoInsertService.insertArchiveTask(issuedParamVo);
        } catch (ParseException e) {
            return ResultEntity.error(e.getMessage());
        }catch (ServiceException e){
            return ResultEntity.error(e.getMessage());
        }
    }

    /**
     * 档案转存任务下发
     */
    @ApiOperation("档案转存任务下发")
    @PostMapping("/insertArchiveUploadTask")
    @Transactional
    public ResultEntity insertArchiveUploadTask(@RequestBody IssuedParamVo issuedParamVo) {
        try {
            return arcArchiveInfoInsertService.insertArchiveTask(issuedParamVo);
        } catch (ParseException e) {
            return ResultEntity.error(e.getMessage());
        }catch (ServiceException e){
            return ResultEntity.error(e.getMessage());
        }
    }

    //数据加密
    @ApiOperation("数据加密")
    @PostMapping("/encrypted")
    public ResultEntity insertHouseLocationNoInfo(String data) {
        String pubKey = "04ac253373f255a68ba0f9fe09e365fadd6c19e9c15b18497aaa6aa11e1097be16e94a648a20e4a60ab60d5c2a1c4f03a1e6d65ddd376cfdab895a4b1d444558dc";
//        String priKey = "6c44b77e9e17e21c13afa1bb33afde166a229a53d34158d2e64ddb8fd4444ff5";
        String priKey = "fba2f90024550bce4b243f5980ffe3d8dfe41897f32deec5b875c188a6715f00";
        // 公钥加密
        String encryptedData = new SM2Util().encryptBySM2(data, pubKey);
        System.out.println("数据入参公钥加密后:**********" + encryptedData);

        return ResultEntity.success(encryptedData);
    }
}


